<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>我的书评_{{ website.name }}</title>
    <link rel="stylesheet" href="/static/css/user.css"/>
    {% include 'common/header.html' %}
</head>
<body class="">

{% include 'common/top.html' %}
<div class="main box_center cf">
    <div class="userBox cf">
        {% include 'user/common.html' %}
        <div class="my_r">
            <div class="my_bookshelf">
                <div class="title cf">
                    <h2 class="fl">我的书评</h2>
                    <div class="fr"></div>
                </div>
                <div class="bookComment">
                    <div class="no_contet no_comment" style="display:none">
                        您还没有发表过评论！
                    </div>
                    <div class="commentBar" id="commentBar">


                    </div>
                </div>
                <div class="pageBox cf" id="commentPage">
                </div>
            </div>
        </div>
    </div>
</div>

{% include 'common/footer.html' %}
{% include 'common/js.html' %}
<script language="javascript" type="text/javascript">
    search(1, 5);

    function search(curr, limit) {

        $.ajax({
            type: "get",
            url: "/user/listCommentByPage",
            data: {'page':curr,'limit':limit},
            dataType: "json",
            success: function (data) {
                if (data.code == 0) {
                    var commentList = data.data;
                    if (commentList.length > 0) {
                        $("#bookCommentTotal").html("("+data.count+"条)");
                        var commentListHtml = "";
                        for (var i = 0; i < commentList.length; i++) {
                            var comment = commentList[i];
                            commentListHtml +=
                            `
                            <div class="comment_list cf">
                                <div class="user_heads fl" vals="389">
                                    <img src="${comment.create_user_photo ? comment.create_user_photo : '/static/images/man.png'}" class="user_head" alt="">
                                    <span class="user_level1" style="display: none;">见习</span>
                                </div>
                                <ul class="pl_bar fr">
                                    <li class="name">${comment.create_user_name}</li>
                                    <li class="dec">${comment.comment_content}</li>
                                    <li class="other cf">
                                        <span class="time fl">${layui.util.toDateString(comment.create_time,  "yyyy-MM-dd HH:mm:ss")}</span>
                                        <span class="fr">
                                            <a href="javascript:void(0);" onclick="javascript:BookDetail.AddAgreeTotal(77,this);" class="zan" style="display: none;">赞<i class="num">(0)</i></a>
                                        </span>
                                    </li>
                                </ul>
                            </div>
                            `;
                        }
                        $("#commentBar").html(commentListHtml);

                        layui.use('laypage', function () {
                            var laypage = layui.laypage;

                            //执行一个laypage实例
                            laypage.render({
                                elem: 'commentPage' //注意，这里的 test1 是 ID，不用加 # 号
                                , count: data.count //数据总数，从服务端得到,
                                , curr: data.page
                                , limit: data.limit
                                , jump: function (obj, first) {


                                    //obj包含了当前分页的所有参数，比如：
                                    //console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                                    //console.log(obj.limit); //得到每页显示的条数


                                    //首次不执行
                                    if (!first) {
                                        search(obj.curr, obj.limit);
                                    } else {

                                    }
                                }
                            });
                        });

                    }


                } else if (data.code == 1001) {
                    //未登录
                    location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);

                }else {
                    layer.alert(data.msg);
                }

            },
            error: function () {
                layer.alert('网络异常');
            }
        })

    }
</script>
</body>
</html>
